package hust.music.action;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import hust.music.action.base.ActionBase;
import hust.music.entity.User;
import hust.music.service.UserModService;

/**
 * UpdatePasswordAction
 * 
 * @author Txazo
 * @since 1.0
 */
@Controller
@Scope("session")
public class UpdatePasswordAction extends ActionBase {

	private static final long serialVersionUID = 1L;

	private String oldpass;
	private String newpass;
	private String repeatpass;

	private String tip21;
	private String tip22;
	private String tip23;
	private String tip24;

	private String type;

	@Autowired
	private UserModService userModService;

	/**
	 * 修改密码
	 * 
	 * @return 逻辑视图
	 * @throws Exception
	 */
	public String update() throws Exception {
		type = "password";
		if (oldpass != null && !oldpass.equals("")) {
			if (newpass != null && !newpass.equals("")) {
				if (newpass != null && !newpass.equals("")) {
					User user = (User) session.get("user");
					if (user.getAuthtoken().equals(oldpass)) {
						if (newpass.equals(repeatpass)) {
							user.setAuthtoken(newpass);
							userModService.update(user);
							session.put("user", user);
							tip24 = "恭喜你成功修改密码";
							return SUCCESS;
						}
						tip23 = "新密码和重复密码不一致";
						return SUCCESS;
					}
					tip21 = "旧密码错误";
					return SUCCESS;
				}
				tip23 = "请输入重复密码";
				return SUCCESS;
			}
			tip22 = "请输入新密码";
			return SUCCESS;
		}
		tip21 = "请输入旧密码";
		return SUCCESS;
	}

	public String getOldpass() {
		return oldpass;
	}

	public void setOldpass(String oldpass) {
		this.oldpass = oldpass;
	}

	public String getNewpass() {
		return newpass;
	}

	public void setNewpass(String newpass) {
		this.newpass = newpass;
	}

	public String getRepeatpass() {
		return repeatpass;
	}

	public void setRepeatpass(String repeatpass) {
		this.repeatpass = repeatpass;
	}

	public String getTip21() {
		return tip21;
	}

	public void setTip21(String tip21) {
		this.tip21 = tip21;
	}

	public String getTip22() {
		return tip22;
	}

	public void setTip22(String tip22) {
		this.tip22 = tip22;
	}

	public String getTip23() {
		return tip23;
	}

	public void setTip23(String tip23) {
		this.tip23 = tip23;
	}

	public String getTip24() {
		return tip24;
	}

	public void setTip24(String tip24) {
		this.tip24 = tip24;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

}